package com.chance.cc.crawler.development.bootstrap.weibo;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.chance.cc.crawler.core.pipeline.result.CrawlerData;

import java.io.*;
import java.nio.charset.Charset;

/**
 * @Author Zhao.Hhuan
 * @Date Create in 2021/1/8 15:00
 * @Description
 *      微博帖子 结果数据查看
 **/
public class WeiboPostDataCheck {

    public static void main(String[] args) {
        String path = "D:\\Download\\weibo_20210112.log";
        String filePath = "D:\\Download\\weibo_test.txt";
        File readFile = new File(path);
        File writeFile = new File(filePath);
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(readFile), "UTF-8"));
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writeFile), Charset.defaultCharset()));

            String s = null;
            int line = 0;
            while ((s = bufferedReader.readLine()) != null){
                line = line + 1;
                try{
                    JSONObject.parseObject(s, CrawlerData.class);
//                    bufferedWriter.write(s);
//                    bufferedWriter.newLine();
//                    bufferedWriter.flush();
                }catch (JSONException e){
                    s = s.replace("\"}{\"", "\"}\n{\"");
                    bufferedWriter.write(s);
                    bufferedWriter.newLine();
                    bufferedWriter.flush();
                    System.out.println(line);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
